/*===========================================================================
Project: 	INCREASING THE DEMAND FOR WORKERS WITH A CRIMINAL RECORD
Info: 		Creates all tables for paper.
Program: 	2_maintables.do
Created: 	January 4, 2022
Edited:  	June 29, 2022 by KG
Purpose: 	Creates main tables for paper on workers with a criminal conviction at the Platform.
Note: 		Set the working directory to the Replication folder that contains this do file.
===========================================================================*/
cap log close
clear all  
version 16, permanently 
discard 

* Install Packages
ssc install gtools, replace
ssc install egenmore, replace
ssc install estout, replace
ssc install distinct, replace

***** Set paths.
global Main "`c(pwd)'"
cd "$Main"

* Data directory
global Data "$Main/analysis_data"

* Table directory 
global Tables "$Main/output_tables"

/*==================================================================
*** RUN A LOG FILE ***
==================================================================*/
global date = "$S_DATE"
global LogPath = "$Main/log"
capture log close
log using "$LogPath/WCC_$date.log", append

/*==================================================================
*** LOAD PROGRAMS ***
==================================================================*/

/***
Program: get_obs
Purpose: gets number of unique firms
***/
program get_obs, rclass
syntax if 

qui: count `if'
local obs = `r(N)'

local n_firms = 0
qui: levelsof firm_id `if', local(firms)

foreach f of local firms{
	local ++n_firms
}

return local counts = "`=string(`obs', "%10.0gc")'" 
return local firms = "`=string(`n_firms', "%10.0gc")'" 

end 

/*==================================================================
*** MAKE TABLES ***
==================================================================*/

/*===========================================================================
Table 2: Desciptive Statistics
=============================================================================*/ 

local n_categories = 11 // max = 11 
local n_industries = 9

* First, we want to get the data that we have in the panel itself 
use "$Data/main_survey_wide.dta", clear 

* Calculate number of managers in the sample
count 
local all_mgrs = string(`r(N)',"%9.3gc")

* Number of managers where their firm industry is nonmissing
count if !missing(sic1)
local ind_mgrs = string(`r(N)',"%9.3gc")

* Number of managers where firm age and firm size is nonmissing
count if !missing(estab_age) | !missing(empsize)
local age_mgrs = string(`r(N)',"%9.3gc")

* Calculate number of managers where information on WC policy is nonmissing
egen nmissingWCC1 = rowmiss(wcc_policy shrm_best_candidate shrm_second_chance shrm_incentivized shrm_customers shrm_regulations shrm_performance)
gen nmissingWCC = nmissingWCC1 == 0 
count if nmissingWCC
local WCC_mgrs = string(`r(N)',"%9.3gc") 

* Collapse by firm_id
collapse (firstnm) industry sic1 (mean) platform_tenure estab_age empsize wcc_policy shrm_best_candidate shrm_second_chance shrm_incentivized shrm_customers shrm_regulations shrm_performance months_on_platform, by(firm_id)

************************************************
** Column 1: Data from the panel 
***********************************************

* Calculate number of firms 
count if !missing(industry)
local ind_obs = string(`r(N)',"%9.3gc")
count if !missing(estab_age) | !missing(empsize)
local age_obs = string(`r(N)',"%9.3gc")
count
local total_obs = string(`r(N)',"%9.3gc")

***** Panel A
* Median firm age
gquantiles estab_age, _pctile percentile(50)
local firmAge = string(r(r1),"%04.1f")

* Median firm size
gquantiles empsize, _pctile percentile(50)
local firmSize = string(r(r1),"%9.1g")

* Generate industry indicators
tab industry, sort gen(ind) 

forvalues ind = 1/`n_industries' {
	su ind`ind', meanonly
	local indshare`ind' =string(`r(mean)', "%03.2f")

	tokenize "`: variable label ind`ind''", parse("==")
	local indlabel`ind' = "`3'"
}

***** Panel B 
* Generate WC hiring policy indicators
foreach var in wcc_policy shrm_best_candidate shrm_second_chance shrm_incentivized shrm_customers shrm_regulations shrm_performance {
	su `var', meanonly
	local `var' = string(r(mean),"%3.2f")
}

* Number of firms with nonmissing SHRM policy
egen nmissingWCC1 = rowmiss(wcc_policy shrm_best_candidate shrm_second_chance shrm_incentivized shrm_customers shrm_regulations shrm_performance)
gen nmissingWCC = nmissingWCC1 == 0 
count if nmissingWCC
local WCC_obs = string(`r(N)',"%9.3gc")

* Mean platform tenure
su platform_tenure, meanonly
local yearsonplatform = string(`r(mean)'/12, "%4.1f")

* Total number of firms 
count
local obs = string(`r(N)',"%9.3gc")

****************************************
********** SHRM REFERENCE **************
****************************************
import excel "$Data/SHRM.xlsx", clear firstrow sheet("Sheet1")

* Calculate mean WC hiring policy adoption rates in SHRM reference data
foreach type in hr manager {
	foreach var in wcc_policy shrm_best_candidate shrm_second_chance shrm_incentivized shrm_customers shrm_regulations shrm_performance {
		su `var' if type == "`type'", meanonly
		local `var'_`type' = string(`=r(mean)/100',"%03.2f")
	}
}

* Number of SHRM firms surveyed
local SHRM_obs "1,228"

****************************************
********* PLATFORM REFERENCE ***********
****************************************
use "$Data/platform_universe.dta", clear 

* Median platform tenure and firm size in the platform data
gquantiles platform_tenure, _pctile percentile(50)
local platform_yearsonplatform = string(`r(r1)'/12, "%4.1f")
gquantiles empsize, _pctile percentile(50)
local platform_empsize = string(`r(r1)', "%7.0gc")

* Industry shares in the platform data
forvalues ind = 1/`n_industries' {
	gen ind`ind' = industry == `"`indlabel`ind''"' if !missing(industry)
	su ind`ind', meanonly
	local platform_indshare`ind' =string(`r(mean)', "%03.2f")
}

* Number of managers and firms in the platform data
get_obs if !missing(industry) | !missing(platform_tenure) | !missing(empsize)
local platform_obs = "`r(counts)'"
local platform_firms = "`r(firms)'"


****************************************
********* INFOGROUP REFERENCE **********
****************************************
use "$Data/infogroup_universe.dta", clear 

* Calculate median firm age and size in Infogroup data
su estab_age, det
drop if estab_age > `r(p95)' 
gquantiles estab_age, _pctile percentile(50)
local IG_firmAge = string(r(r1),"%04.1f")
gquantiles empsize, _pctile percentile(50)
local IG_firmSize = string(r(r1),"%9.1g")

* Mean industry shares in Infogroup data
forvalues ind = 1/`n_industries' {
	gen ind`ind' = sic == `"`indlabel`ind''"' if !missing(sic)
	su ind`ind', meanonly
	local IG_indshare`ind' =string(`r(mean)', "%03.2f")
}   

** This counts is tough since we have difference coverage for each variable 
count if !missing(estab_age) | !missing(empsize)
local IG_obs = string(`r(N)',"%14.3gc")

count if !missing(sic) 
local IG_ind = string(`r(N)',"%14.3gc")

* Generate LaTeX file for the table
file open fh using "$Tables/t2_summarystats.tex", write replace

file write fh ///
"\begin{table}[htpb!]" _n /// 
"\centering" _n ///
"\caption{\\ Descriptive Statistics}" _n ///
"\label{table_summarystats}"	_n /// 
"\small\begin{tabular}{l ccc }" _n ///
"\toprule" _n

file write fh ///
									"	&   \multicolumn{1}{c}{Experimental}  	&&  \multicolumn{1}{c}{Infogroup} \\" _n ///  
			"A. Firm Characteristics	&   \multicolumn{1}{c}{Sample}  		&&  \multicolumn{1}{c}{Database} \\" _n ///  
"\cmidrule(lr){2-2} \cmidrule(lr){4-4}" _n ///
"\hspace{5 pt} Median Firm Age 						& `firmAge' 							&& `IG_firmAge'            \\ \addlinespace" _n ///  
"\hspace{5 pt} Median Number of Employees						& `firmSize'							&& `IG_firmSize'            \\ \addlinespace" _n /// 
"\hspace{5 pt} `indlabel1' 						& `indshare1'							&& `IG_indshare1'         \\ \addlinespace" _n ///
"\hspace{5 pt} `indlabel2' 						& `indshare2'							&& `IG_indshare2'         \\ \addlinespace" _n ///
"\hspace{5 pt} `indlabel3' 						& `indshare3'							&& `IG_indshare3'         \\ \addlinespace" _n ///
"\hspace{5 pt} `indlabel4' 						& `indshare4'							&& `IG_indshare4'         \\ \addlinespace" _n ///
"\hspace{5 pt} `indlabel5' 						& `indshare5'							&& `IG_indshare5'         \\ \addlinespace" _n ///
"\hspace{5 pt} `indlabel6' 						& `indshare6'							&& `IG_indshare6'         \\ \addlinespace" _n ///
"\hspace{5 pt} `indlabel7' 						& `indshare7'							&& `IG_indshare7'         \\ \addlinespace" _n ///
"\hspace{5 pt} `indlabel8' 						& `indshare8'							&& `IG_indshare8'         \\ \addlinespace" _n ///
"\hspace{5 pt} `indlabel9' 						& `indshare9'							&& `IG_indshare9'         \\ \addlinespace" _n ///
"\addlinespace" _n ///
"Firms with Nonmissing Age or Number Employees											& `age_obs' 							&& `IG_obs'	       \\ \addlinespace" _n ///
"\hspace{5 pt} with Nonmissing Industry Classification 		& `ind_obs'								&& `IG_ind'            \\ \addlinespace" _n ///
									"	&   \multicolumn{1}{c}{Experimental}  	&&  \multicolumn{1}{c}{SHRM} \\ " _n ///  
"B. Hiring Policies and Views								&   \multicolumn{1}{c}{Sample}  		&&  \multicolumn{1}{c}{Survey} \\" _n ///  
"\cmidrule(lr){2-2} \cmidrule(lr){4-4}" _n ///
"\hspace{5 pt} Firm-Wide WC Hiring Policy 							& `wcc_policy'	 						&&  `wcc_policy_hr'	       \\ \addlinespace" _n ///
"\hspace{5 pt} Consider WCs Because Best Candidate 					& `shrm_best_candidate'					&&  `shrm_best_candidate_hr'      \\ \addlinespace" _n ///
"\hspace{5 pt} Consider WCs Because Second Chances Are Important 				& `shrm_second_chance'					&&  `shrm_second_chance_hr'	 \\ \addlinespace" _n ///
"\hspace{5 pt} Consider WCs Because of Financial Incentives 		& `shrm_incentivized'					&&  `shrm_incentivized_hr'	 \\ \addlinespace" _n ///
"\hspace{5 pt} Concerned About Customer Reactions 					& `shrm_customers'	 					&&  `shrm_customers_hr'	 	 \\ \addlinespace" _n ///
"\hspace{5 pt} Concerned About Local, State, or Federal Regulations 				& `shrm_regulations'					&&  `shrm_regulations_hr'	 \\ \addlinespace" _n ///
"\hspace{5 pt} Concerned About Performance 							& `shrm_performance'					&&  `shrm_performance_hr'	 \\ \addlinespace" _n ///
"\addlinespace" _n ///
"Firms with Nonmissing Hiring Policy Information 						& `WCC_obs' 							&& 	`SHRM_obs'				\\" _n ///
"\addlinespace" _n ///

file write fh ///
"\bottomrule  " _n /// 
"\end{tabular}" _n /// 
"\begin{tabular}{p{\textwidth}}" _n /// 
"\footnotesize{\hspace{1em}{\emph{Notes.}}" _n /// 
"This table reports descriptive statistics for the experimental sample comprised of the 1,095 hiring " _n /// 
"managers from 913 businesses that completed the experiment." _n /// 
"Panel A reports statistics for the `total_obs' firms in our sample " _n ///
"matched to the Infogroup Historical Business Database (column 1) and all firms in the Infogroup Historical Business Database (column 2), which contains basic profile data for more than a million U.S. businesses." _n /// 
"The industry characteristics are further limited to the `ind_obs' firms in our sample with that data available in the Infogroup Database." _n ///
"Panel B reports information on WC hiring policies, where information for the broader set of U.S. businesses comes from a nationwide survey of over 1,000 HR professionals commissioned by the Society for Human Resource Management. " _n ///
"}" _n /// 
"\end{tabular}" _n /// 
"\end{table}"  _n _n _n _n _n 

file close fh
macro drop fh


/*===========================================================================
Table 3: Randomization Assessment - p-Values from Regressions of Covariates 
	  on Treatment Indicators
=============================================================================*/

set more off
use "$Data/main_survey_wide.dta", clear

tab industry, sort gen(ind) 
tab modal_category, sort gen(jobcategory) 

* Get industries and categories 
local top_n 9
forvalues ind = 1/`top_n' {
	tokenize "`: variable label ind`ind''", parse("==")
	local indlabel`ind' = "`3'"
}

* Aggregate the smallest 5 industries: Wholesale, Public Admin, Finance, Construction, and Nonclassifiable
gen ind_agg = ind5 + ind6 + ind7 + ind8 + ind9
local indlabel_agg = "Nonclassifiable \& Misc. Industries"
forvalues j = 1/`top_n' {
	tokenize "`: variable label jobcategory`j''", parse("==")
	local joblabel`j' = "`3'"
}

rename months_on_platform months
rename info_randomization info 

local covariates "cust_int high_val hr exp_hire wcc_policy months vacant_job ind1 ind2 ind3 ind4 ind5 ind6 ind7 ind8 ind_agg jobcategory1 jobcategory2 jobcategory3 jobcategory4 jobcategory5 empsize estab_age" // service back_office manufacturing
local treat "subsidy_rate ins_cap past_jobs years_elapsed ue_rate info"

foreach v in ind1 ind2 ind3 jobcategory1 jobcategory2 jobcategory3 {
	replace `v' = 0 if missing(`v')
}

* Calculate p-values of regressions of covariates on treatment indicators
foreach iX in `covariates'{
	foreach jX in `treat'{
		reg `iX' i.`jX', cluster(firm_id)
		local p_`iX'_`jX' =substr(string(Ftail(e(df_m), e(df_r), e(F)), "%10.3fc"), 2, .)
		di `p_`iX'_`jX''

		* Get number of observations
		get_obs if e(sample)
		local n_`iX' = "`r(counts)'"
		local f_`iX' = "`r(firms)'"
	}	
}

* Generate LaTeX file for the table
file open fh using "$Tables/t3_balance.tex", write replace

file write fh ///
"\begin{table}[htpb!]" _n ///
"\centering" _n ///	
"\captionsetup{justification=centering}" _n ///
"\caption{\\ Randomization Assessment \\ p-values from Regressions of Covariates on Treatment Indicators}" _n ///
"\label{table_randomization} " _n ///
"\footnotesize\begin{tabular}{l cccccc}" _n ///
"\toprule " _n ///
"	&  \multicolumn{1}{c}{Wage} 	&  \multicolumn{1}{c}{Crime}	&\multicolumn{1}{c}{Performance}&  \multicolumn{1}{c}{Clean}		&  \multicolumn{1}{c}{Unemp.}	&  \multicolumn{1}{c}{Shown}  \\  " _n ///
"A. Firm Characteristics and Policies 	& \multicolumn{1}{c}{Subsidy} 	&  \multicolumn{1}{c}{Insurance}&  \multicolumn{1}{c}{History} 	&  \multicolumn{1}{c}{Record}		&  \multicolumn{1}{c}{Rate}		&  \multicolumn{1}{c}{Info.}  	\\  " _n ///
"\cline{2-2}\cline{3-3}\cline{4-4}\cline{5-5}\cline{6-6}\cline{7-7} " _n ///
"\addlinespace" _n

*************************************************************

file write fh "\hspace{5 pt} Firm Age 								&  `p_estab_age_subsidy_rate' 	&  `p_estab_age_ins_cap' 		&  `p_estab_age_past_jobs' 		&  `p_estab_age_years_elapsed' 		&  `p_estab_age_ue_rate' 		&  `p_estab_age_info' 			\\ \addlinespace" _n
file write fh "\hspace{5 pt} Employees 								&  `p_empsize_subsidy_rate' 	&  `p_empsize_ins_cap' 			&  `p_empsize_past_jobs' 		&  `p_empsize_years_elapsed' 		&  `p_empsize_ue_rate' 			&  `p_empsize_info' 			\\ \addlinespace" _n

file write fh "\hspace{5 pt} `indlabel1' 						& `p_ind1_subsidy_rate'			& `p_ind1_ins_cap'				& `p_ind1_past_jobs'			& `p_ind1_years_elapsed'			& `p_ind1_ue_rate'				& `p_ind1_info' 					\\ \addlinespace" _n 
file write fh "\hspace{5 pt} `indlabel2' 						& `p_ind2_subsidy_rate'			& `p_ind2_ins_cap'				& `p_ind2_past_jobs'			& `p_ind2_years_elapsed'			& `p_ind2_ue_rate'				& `p_ind2_info' 					\\ \addlinespace" _n 
file write fh "\hspace{5 pt} `indlabel3' 						& `p_ind3_subsidy_rate'			& `p_ind3_ins_cap'				& `p_ind3_past_jobs'			& `p_ind3_years_elapsed'			& `p_ind3_ue_rate'				& `p_ind3_info' 					\\ \addlinespace" _n 
file write fh "\hspace{5 pt} `indlabel4' 						& `p_ind4_subsidy_rate'			& `p_ind4_ins_cap'				& `p_ind4_past_jobs'			& `p_ind4_years_elapsed'			& `p_ind4_ue_rate'				& `p_ind4_info' 					\\ \addlinespace" _n 
file write fh "\hspace{5 pt} `indlabel_agg' 						& `p_ind_agg_subsidy_rate'			& `p_ind_agg_ins_cap'				& `p_ind_agg_past_jobs'			& `p_ind_agg_years_elapsed'			& `p_ind_agg_ue_rate'				& `p_ind5_info' 					\\ \addlinespace" _n 
file write fh "\hspace{5 pt} Firm-Wide WC Hiring Policy 			&  `p_wcc_policy_subsidy_rate' 	&  `p_wcc_policy_ins_cap' 		&  `p_wcc_policy_past_jobs' 	&  `p_wcc_policy_years_elapsed' 	&  `p_wcc_policy_ue_rate' 		&  `p_wcc_policy_info' 			\\ \addlinespace" _n
file write fh "\hspace{5 pt} Platform Tenure (Years)				&  `p_months_subsidy_rate' 		&  `p_months_ins_cap' 			&  `p_months_past_jobs'  		&  `p_months_years_elapsed'  		&  `p_months_ue_rate'	  		&  `p_months_info'  		\\ \addlinespace" _n
file write fh "\hspace{5 pt} Job Vacancy Rate 						&  `p_vacant_job_subsidy_rate' &  `p_vacant_job_ins_cap' 		&  `p_vacant_job_past_jobs'  	&  `p_vacant_job_years_elapsed'  	&  `p_vacant_job_ue_rate'	  	&  `p_vacant_job_info'  	\\ \addlinespace" _n

file write fh "\addlinespace B. Firm Characteristics and Policies \\ \addlinespace" _n 

file write fh "\hspace{5 pt} Job Involves Customer Interactions 	&  `p_cust_int_subsidy_rate' 	&  `p_cust_int_ins_cap' 		&  `p_cust_int_past_jobs'   	&  `p_cust_int_years_elapsed'   	&  `p_cust_int_ue_rate'			&  `p_cust_int_info'   \\ \addlinespace" _n
file write fh "\hspace{5 pt} Job Involves High-Value Inventory  	&  `p_high_val_subsidy_rate' 	&  `p_high_val_ins_cap' 		&  `p_high_val_past_jobs'   	&  `p_high_val_years_elapsed'   	&  `p_high_val_ue_rate'			&  `p_high_val_info'   \\ \addlinespace" _n
file write fh "\hspace{5 pt}	Modal Job is `joblabel1' 						& `p_jobcategory1_subsidy_rate'	& `p_jobcategory1_ins_cap'		& `p_jobcategory1_past_jobs'	& `p_jobcategory1_years_elapsed'	& `p_jobcategory1_ue_rate'		& `p_jobcategory1_info'  				\\ \addlinespace" _n 
file write fh "\hspace{5 pt}	Modal Job is `joblabel2' 						& `p_jobcategory2_subsidy_rate'	& `p_jobcategory2_ins_cap'		& `p_jobcategory2_past_jobs'	& `p_jobcategory2_years_elapsed'	& `p_jobcategory2_ue_rate'		& `p_jobcategory2_info'  				\\ \addlinespace" _n 
file write fh "\hspace{5 pt}	Modal Job is `joblabel3' 						& `p_jobcategory3_subsidy_rate'	& `p_jobcategory3_ins_cap'		& `p_jobcategory3_past_jobs'	& `p_jobcategory3_years_elapsed'	& `p_jobcategory3_ue_rate'		& `p_jobcategory3_info'  				\\ \addlinespace" _n 	
file write fh "\hspace{5 pt}	Modal Job is `joblabel4' 						& `p_jobcategory4_subsidy_rate'	& `p_jobcategory4_ins_cap'		& `p_jobcategory4_past_jobs'	& `p_jobcategory4_years_elapsed'	& `p_jobcategory4_ue_rate'		& `p_jobcategory4_info'  				\\ \addlinespace" _n 	
file write fh "\hspace{5 pt}	Modal Job is `joblabel5' 						& `p_jobcategory5_subsidy_rate'	& `p_jobcategory5_ins_cap'		& `p_jobcategory5_past_jobs'	& `p_jobcategory5_years_elapsed'	& `p_jobcategory5_ue_rate'		& `p_jobcategory5_info'  				\\ \addlinespace" _n 	


file write fh "\hline \addlinespace Firms										& `f_ind1' 						& `f_ind1' 						& `f_ind1' 						& `f_ind1' 							& `f_ind1' 						& `f_ind1' 						\\ \addlinespace" _n
file write fh "Managers												& `n_ind1' 						& `n_ind1' 						& `n_ind1' 						& `n_ind1' 							& `n_ind1' 						& `n_ind1' 						\\ \addlinespace" _n				


file write fh ///
"\bottomrule  " _n ///
"\end{tabular}"  _n ///
"\begin{tabular}{ p{\linewidth}}"  _n ///
"\footnotesize{\hspace{1em}{\emph{Notes.}}" _n ///
"This table reports balance tests for the estimation sample described in Table~\ref{table_summarystats}." _n ///
"Each cell reports the p-value of an F-statistic from a separate regression of the baseline covariates" _n /// 
"listed in the rows on indicator variables for each value of the treatments listed in the columns. Standard errors are clustered at the firm level. Nonclassifiable \& Misc. Industries is an aggregation of Nonclassifable, Construction, Finance, Public Administration, and Wholesale Trade industries." _n ///
"See the Table~\ref{table_summarystats} notes for additional details on the outcomes and sample." _n /// 
"}"  _n /// 
"\end{tabular}" _n ///
"\end{table} "  _n _n _n _n _n 


file close fh
macro drop fh

/*===========================================================================
Table 4: Results for Perception/Information Updating
===========================================================================*/

* IV regressions and calculations of number managers and firms for Panel A
set more off
use "$Data/main_survey_wide.dta", clear 

gen itr_info = info_randomization*perception_gap
eststo clear 
eststo: reg 	ln_posterior itr_info  ln_prior hire_sub if info_type == 1 & !missing(hire_sub_posterior) , first cluster(firm_id)
su ln_posterior if e(sample), meanonly
estadd local DV = string(`r(mean)',"%03.2f")
get_obs if e(sample)
estadd local mgrs = r(counts)
estadd local firms = r(firms)

eststo: reg 	hire_sub_posterior ln_posterior  ln_prior hire_sub if info_type == 1, first cluster(firm_id)
su hire_sub_posterior if e(sample), meanonly
estadd local DV = string(`r(mean)',"%03.2f")

get_obs if e(sample)
estadd local mgrs = r(counts)
estadd local firms = r(firms)

eststo: ivreg2 hire_sub_posterior (ln_posterior = itr_info) ln_prior hire_sub if info_type == 1, first cluster(firm_id)
su hire_sub_posterior if e(sample), meanonly
estadd local DV = string(`r(mean)',"%03.2f") 
estadd local F_stat = string(`e(widstat)',"%04.2f")

get_obs if e(sample)
estadd local mgrs = r(counts)
estadd local firms = r(firms)

eststo: reg hire_sub_posterior itr_info ln_prior hire_sub if info_type == 1, first cluster(firm_id)
su hire_sub_posterior if e(sample), meanonly
estadd local DV = string(`r(mean)',"%03.2f")

get_obs if e(sample)
estadd local mgrs = r(counts)
estadd local firms = r(firms)

* Make Panel A - Impact of High-Performance Information Treatment
esttab using "$Tables/t4_ivtable.tex", replace  keep(itr_info ln_posterior) ///
posthead("&First & & &Reduced \\" "A. Impact of High-Performance Information&Stage &OLS&IV&Form\\" "\cmidrule(lr){2-2}\cmidrule(lr){3-3}\cmidrule(lr){4-4}\cmidrule(lr){5-5}" "\addlinespace") /// 
booktabs nomtitles nonum coeflabels(itr_info "\hspace{5pt} Shown Info $\times$ (Signal - Prior Belief)" ln_posterior "\hspace{5pt} ln(Posterior Belief)") /// 
nostar stats(DV F_stat firms mgrs , label("Mean: Dependent Variable" "Kleibergen-Paap: Weak Identification F-Stat" "Firms" "Managers" )) ///
title("High- and Low-Performance Information") postfoot("\cmidrule(lr){1-5}""\addlinespace") prefoot("\addlinespace" "\cmidrule(lr){1-5}") ///
prehead("\begin{table}[htbp]\centering" "\caption{\\ High- and Low-Performance Information}" "\label{tab:IV_table}" "\begin{tabular}{l*{4}{c}}" "\toprule") substitute(\_ _) se

* IV regressions calculations of number managers and firms for panel B
eststo clear 
eststo: reg ln_posterior itr_info  ln_prior hire_sub if info_type == 2 & !missing(hire_sub_posterior), first cluster(firm_id)
su ln_posterior if e(sample), meanonly
estadd local DV = string(`r(mean)',"%03.2f")
get_obs if e(sample)
estadd local mgrs = r(counts)
estadd local firms = r(firms)

eststo: reg hire_sub_posterior ln_posterior  ln_prior hire_sub if info_type == 2, first cluster(firm_id)
su hire_sub_posterior if e(sample), meanonly
estadd local DV = string(`r(mean)',"%03.2f")
get_obs if e(sample)
estadd local mgrs = r(counts)
estadd local firms = r(firms)

eststo: ivreg2 hire_sub_posterior (ln_posterior = itr_info) ln_prior hire_sub if info_type == 2, first cluster(firm_id)
su hire_sub_posterior if e(sample), meanonly
estadd local DV = string(`r(mean)',"%03.2f")
estadd local F_stat = string(`e(widstat)',"%04.2f")
get_obs if e(sample)
estadd local mgrs = r(counts)
estadd local firms = r(firms)

eststo: reg hire_sub_posterior itr_info ln_prior hire_sub if info_type == 2, first cluster(firm_id)
su hire_sub_posterior if e(sample), meanonly
estadd local DV = string(`r(mean)',"%03.2f")
get_obs if e(sample)
estadd local mgrs = r(counts)
estadd local firms = r(firms)

* Make Panel B - Impact of Low-Performance Information Treatment
esttab using "$Tables/t4_ivtable.tex", append keep(itr_info ln_posterior) ///
posthead("&First & & &Reduced \\" "B. Impact of Low-Performance Information&Stage &OLS&IV&Form\\" "\cmidrule(lr){2-2}\cmidrule(lr){3-3}\cmidrule(lr){4-4}\cmidrule(lr){5-5}") /// 
booktabs nomtitles nonum coeflabels(itr_info "\hspace{5pt} Shown Info $\times$ (Signal - Prior Belief)" ln_posterior "\hspace{5pt} ln(Posterior Belief)") /// 
nostar stats(DV F_stat firms mgrs , label("Mean: Dependent Variable" "Kleibergen-Paap: Weak Identification F-Stat" "Firms" "Managers" )) ///
title("High- and Low-Performance Information") postfoot("\bottomrule""\end{tabular}" ) nofloat fragment se

* Add table notes 
file open fh using "$Tables/t4_ivtable.tex", write append 
file write fh ///
"\begin{tabular}{ p{\linewidth}}" _n ///
"\footnotesize{\hspace{1em}{\emph{Notes.}}" _n ///
"This table reports estimates of the impact of high- and low-performance information on firm beliefs and willingness to work with WCs. Standard errors clustered by business are in parentheses." _n ///
"Panel A reports results for managers who were shown information on the fraction of 5-star ratings." _n ///
"Panel B reports results for managers who were shown information on the fraction of no-shows and either 1- or 2-star ratings. " _n ///
"Column 1 reports first stage estimates of the effect of information on posterior beliefs. " _n ///
"Column 2 reports OLS estimates of the cross-sectional relationship between posterior beliefs and willingness to work with WCs." _n ///
"Column 3 reports IV estimates of the causal impact of a change in posterior beliefs on willingness to work with WCs." _n ///
"Column 4 reports reduced form estimates of the effect of information on willingness to work with WCs." _n ///
"See Section \ref{Section-Info} of the text for additional details." _n ///
"}" _n ///
"\end{tabular}" _n ///
"\end{table}" _n ///

file close fh
macro drop fh


log close
exit
